package pri.jz.keeper.db

import androidx.lifecycle.LiveData
import androidx.room.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import pri.jz.keeper.entity.User

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS:在此构写room数据库的增删查改
 */
@Dao
interface UserDao {
    @Query("select * from user where id = :id")
    fun findById(id: Int) : LiveData<User?>

    @Query("select * from user")
    fun getAll() : Flow<List<User>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(user: User)

    @Delete
    fun delete(user: User)

    @Update
    fun update(user: User)
}